import { Component, Injector, ViewEncapsulation, ViewChild, OnInit } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { MaterialChargeServiceProxy, PipelineListDto, MaterialForProduct, GetReturnMaterialOutput } from '@shared/service-proxies/service-proxies';

@Component({
  selector: 'yl10',
  templateUrl: './yl10.component.html',
  styleUrls: ['./yl10.component.less'],
  encapsulation: ViewEncapsulation.None
})

export class YL10ModalComponent extends AppComponentBase implements OnInit {
  subTaskCode = '';
  drawingCode = '';

  saving = false;

  filterText = '';

  pipe: PipelineListDto = new PipelineListDto();

  outs = new Array<MaterialForProduct>();
  returns = new Array<GetReturnMaterialOutput>();

  //table cols
  cols: any[];
  selectedColumns: any[];
  expandedRowKeys = [];
  goods = [];

  constructor(
    injector: Injector,
    private _materialChargeServiceProxy: MaterialChargeServiceProxy,
  ) {
    super(injector);
  }

  ngOnInit(): void {
    this.cols = [
      { field: 'requestedTaskNum', header: '任务号', width: '150px', isDefaultSelect: true },
      { field: 'requestedDrawingNum', header: '图号', width: '120px', isDefaultSelect: true },
      { field: 'displayName', header: '名称', width: '100px', isDefaultSelect: true },
      { field: 'furnaceBatch', header: '炉批号', width: '100px' },
      { field: 'invCode', header: '质检编号', width: '100px', isDefaultSelect: true },
      { field: 'materialModel', header: '牌号', width: '100px', isDefaultSelect: true },
      { field: 'certificateNo', header: '合格证', width: '100px', isDefaultSelect: true },
      { field: 'materialCode', header: '物质编码', width: '100px' },
      { field: 'materialStatus', header: '材料状态', width: '100px' },
      { field: 'specification', header: '规格', width: '100px' },
      { field: 'size', header: '尺寸', width: '100px' },
      { field: 'unit', header: '计量单位', width: '100px' },
      { field: 'techCondition', header: '技术状态', width: '100px' }
    ];

    this.selectedColumns = this.cols.filter(el => {
      return el.isDefaultSelect;
    });
  }


  load(pipe: PipelineListDto): void {
    this.pipe = pipe;

    this.getOuts();

  }

  getOuts() {
    //this.goods=[];
    this._materialChargeServiceProxy.getOuts(this.pipe.id)
      .subscribe(result => {
        this.outs = result;
        this.outs.forEach(el => {
          this.expandedRowKeys[el.id] = 1;
        });
        this.outs.forEach(item => {
          this.goods.push(item.id);
        });
        this.getReturn();

      });
  }
  getReturn() {
    //  console.log(this.goods);
    //  for (let i = 0; i <  this.goods.length-1; i++) {
    //    for (let j = i+1; j < this.goods.length; j++) {
    //     if(this.goods[i]==(this.goods[j])){
    //       this.goods.concat(i);
    //   }

    //    }

    //  }
    console.log(this.goods);
    this._materialChargeServiceProxy.getReturn(this.pipe.id)
      .subscribe(result => {
        this.returns = result;


      });
  }

  reloadPage(): void {
    this.getOuts();
  }

}
